<template>
    <div class="nvb_user_info_menu">
        <a-image
            v-show="store.userInfo.avatar"
            :src="store.userInfo.avatar"
            alt="avatar"
        />
        <a-dropdown @select="onSelect">
            <div class="nvb_user_info_menu_dropdown">
                <span class="nvb_user_info_menu_dropdown_span">
                    {{ store.userInfo.username }}
                </span>
                <IconDown></IconDown>
            </div>
            <template #content>
                <a-doption
                    v-for="item in dOptionList"
                    :key="item.name"
                    :value="item.name"
                >
                    {{ item.title }}
                </a-doption>
            </template>
            <template #footer>
                <a-doption :value="'logout'">注销退出</a-doption>
            </template>
        </a-dropdown>
    </div>
</template>

<script setup lang="ts">
import { IconDown } from '@arco-design/web-vue/es/icon'
import { useStore } from '@/stores'
import type { ITab } from '@/types'
import { useRouter } from 'vue-router'

const store = useStore()
const router = useRouter()

const dOptionList: ITab[] = [
    {
        name: 'log_list',
        title: '系统日志',
    },
    {
        name: 'login',
        title: '用户登录',
    },
]

function onSelect(value: string) {
    if (value === 'logout') {
        store.logout()
        router.push({ name: 'login' })
        return
    } else if (value === 'login') {
        router.push({ name: 'login' })
        return
    }
    router.push({ name: value })
}
</script>

<style lang="scss">
.nvb_user_info_menu {
    display: flex;
    .arco-image-img {
        width: 30px;
        height: 30px;
        border-radius: 50px;
        cursor: pointer;
    }

    .nvb_user_info_menu_dropdown {
        display: flex;
        align-items: center;
        cursor: pointer;

        .nvb_user_info_menu_dropdown_span {
            margin: 0 5px;
        }
    }
}
</style>
